package psn.zjk.spring.zookeeper;

import org.apache.zookeeper.*;
import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Stat;
import psn.zjk.spring.utils.JacksonUtils;

import java.io.IOException;
import java.util.ArrayList;

/**
 * @USER white
 * @DATETIME 2020/11/24 20:57
 */
public class ZkClient implements Watcher {
    ZooKeeper zooKeeper;
    public ZkClient() throws IOException {
         zooKeeper = new ZooKeeper("127.0.0.1", 2181, this);
    }

    public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
        ZkClient zkClient = new ZkClient();
        zkClient.x();
        Thread.sleep(1000010);
    }


    public void x() throws KeeperException, InterruptedException {
        Stat a = zooKeeper.exists("/a", true);
        ArrayList<ACL> aclList = new ArrayList<>();
//        aclList.add(ACL.signature())
//        zooKeeper.create("/dubbo","".getBytes(),aclList, CreateMode.PERSISTENT)
    }


    @Override
    public void process(WatchedEvent event) {
        System.out.println(JacksonUtils.object2Json(event));
    }
}
